//
//  YSSqliteModelTool.h
//  YSSqliteTool_Example
//
//  Created by Kyson on 2018/12/4.
//  Copyright © 2018 kysonyangs. All rights reserved.
//
//  sqlite操作模型工具类

#import <Foundation/Foundation.h>
#import "YSModelProtocol.h"

typedef NS_ENUM(NSUInteger, RelationType) {
    RelationTypeEqual,      ///< ==
    RelationTypeMore,       ///< >
    RelationTypeMoreEqual,  ///< >=
    RelationTypeLess,       ///< <
    RelationTypeLessEqual,  ///< <=
};

@interface YSSqliteModelTool : NSObject

/**
 通过类名创建表
 */
+ (BOOL)createTable:(Class)cls uid:(NSString *)uid;

/**
 是否需要更新表结构
 */
+ (BOOL)isTableRequiredUpdate:(Class)cls uid:(NSString *)uid;

/**
 更新表结构
 */
+ (BOOL)updateTable:(Class)cls uid:(NSString *)uid;

/**
 通过模型更新数据库
 */
+ (BOOL)saveOrUpdateModel:(id)model uid:(NSString *)uid;

/**
 删除模型
 */
+ (BOOL)deleteModel:(id)model uid:(NSString *)uid;

/**
 根据条件进行删除
 */
+ (BOOL)deleteModel:(Class)cls whereStr:(NSString *)whereStr uid:(NSString *)uid;

/**
 根据条件进行删除

 @param cls 类名
 @param name 字段名
 @param type 操作符
 @param value 值
 @param uid 用户id
 @return 是否成功
 */
+ (BOOL)deleteModel:(Class)cls columnName:(NSString *)name relationType:(RelationType)type value:(id)value uid:(NSString *)uid;

/**
 查询数据库所有数据
 */
+ (NSArray *)queryAllModels:(Class)cls uid:(NSString *)uid;

/**
 根据条件进行查询

 @param cls 类名
 @param name 字段名
 @param type 操作符
 @param value 值
 @param uid 用户id
 @return 结果数组
 */
+ (NSArray *)queryModels:(Class)cls columnName:(NSString *)name relationType:(RelationType)type value:(id)value uid:(NSString *)uid;

+ (NSArray *)queryModels:(Class)cls WithSql:(NSString *)sql uid:(NSString *)uid;

@end
